Code sample Home

Offset all closed polylines

void DemoEntOffset (HANDLE hLcWnd)
{
  #define KEY_NEW_ENT 100321
  HANDLE hBlock, hEnt, hEnt2;
  bool bClosed, bNewEnts;
  double OffDist;
  int Key;

  bNewEnts = true; 
  OffDist = -1.0;
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_BLOCK );
  hEnt = lcBlockGetFirstEnt( hBlock );
  while( hEnt != 0 ){
    if (lcEntType( hEnt, LC_ENT_POLYLINE ) == TRUE){
      bClosed = lcPropGetBool( hEnt, LC_PROP_PLINE_CLOSED );
      if (bClosed){
        if (bNewEnts){
          // add new entity and offset it
          Key = lcPropGetInt( hEnt, LC_PROP_ENT_KEY );
          if (Key != KEY_NEW_ENT){
            hEnt2 = lcBlockAddClone( hBlock, hEnt );
            if (hEnt2){
              lcEntOffset( hEnt2, OffDist );
              lcPropPutInt( hEnt2, LC_PROP_ENT_KEY, KEY_NEW_ENT );
              lcPropPutInt( hEnt2, LC_PROP_ENT_COLOR, lcColorRGB(100,200,50) );
            }
          }
        }else{
          // offset exist entity
          lcEntOffset( hEnt, OffDist );
        }
      }
    }
    hEnt = lcBlockGetNextEnt( hBlock, hEnt );
  }
  lcWndRedraw( hLcWnd );
}
This will create a drawing as shown on the picture below: